package csdn;

import java.util.Comparator;
import java.util.Objects;
import java.util.PriorityQueue;

class Card{
    public int rank;
    public String suit;
    public Card(int rank, String suit) {
        this.rank = rank;
        this.suit = suit;
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || !(o instanceof Card)) return false;
        Card card = (Card) o;
        return rank == card.rank && Objects.equals(suit, card.suit);
    }
}
class CardComparator implements Comparator<Card>{
    @Override
    // 返回值:
    // < 0: 表示 o1 指向的对象小于 o2 指向的对象
    // == 0: 表示 o1 指向的对象等于 o2 指向的对象
    // > 0: 表示 o1 指向的对象等于 o2 指向的对象
    public int compare(Card o1, Card o2) {
        if (o1 == o2) {
            return 0;
        }
        if (o1 == null) {
            return -1;
        }
        if (o2 == null) {
            return 1;
        }
        return o1.rank - o2.rank;
    }
}
public class Csdn3 {
    public static void main(String[] args) {

        Card p = new Card(1, "♠");
        Card q = new Card(2, "♠");
        Card o = new Card(1, "♠");
        //定义比较器对象
        CardComparator cmptor = new CardComparator();
        // 使用比较器对象进行比较
        System.out.println(cmptor.compare(p, o)); // == 0，表示牌相等
        System.out.println(cmptor.compare(p, q)); // < 0，表示 p 比较小
        System.out.println(cmptor.compare(q, p)); // > 0，表示 q 比较大
    }
    public static void main2(String[] args) {
        Card c1 = new Card(1, "♠");
        Card c2 = new Card(1, "♠");
//        Card c3 = c1;
//        System.out.println(c1>c2);编译报错
//        System.out.println(c1==c2);//打印false，因为c1和c2指向的是不同对象
//        System.out.println(c1<c2);编译报错
//        System.out.println(c1==c3);//打印false，因为c1和c2指向的是不同对象
        System.out.println(c1.equals(c2));

    }
    public static void main3(String[] args) {
        String str1=new String("abcd");
        String str2=new String("abcd");
        System.out.println(str1.equals(str2));
    }
    public static void main1(String[] args) {
        int a=12;
        int b=55;
        System.out.println(a > b);
        System.out.println(a == b);
        System.out.println(a<b);

        //字符的比较根据字符所对应ASCII值来比较大小
        char ch1='a';
        char ch2='b';
        char ch3='c';
        System.out.println(ch1>ch2);
        System.out.println(ch1==ch2);
        System.out.println(ch1<ch2);

        boolean b1=true;
        boolean b2=false;
        System.out.println(b1==b2);
        System.out.println(b1!=b2);
    }
}
